/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package posturecorrectionsystem.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JLabel;
import javax.swing.JWindow;

/**
 *
 * @author ahmet
 */
public class RestrictionWindow extends JWindow{
    private Timer timer;

    private JLabel messageLabel;

    public RestrictionWindow() {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setSize(screenSize);

        messageLabel = new JLabel("", JLabel.CENTER);
        messageLabel.setFont(new Font(Font.SERIF, Font.PLAIN, 30));

        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(messageLabel, BorderLayout.CENTER);

        getContentPane().addMouseListener(new MouseListener() {

            public void mouseClicked(MouseEvent me) {

            }

            public void mousePressed(MouseEvent me) {

            }

            public void mouseReleased(MouseEvent me) {

            }

            public void mouseEntered(MouseEvent me) {

            }

            public void mouseExited(MouseEvent me) {

            }
        });

        getContentPane().addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent ke) {
                super.keyPressed(ke);
            }

            @Override
            public void keyReleased(KeyEvent ke) {
                super.keyReleased(ke);
            }

            @Override
            public void keyTyped(KeyEvent ke) {
                super.keyTyped(ke);
            }
        });
        setAlwaysOnTop(true);
    }

    public void activate(String message, boolean withTimer, int ms) {
        messageLabel.setText(message);
        if (withTimer) {
            timer = new Timer("Restriction window timer");
            timer.schedule(new CloseRestrictionWindow(this), ms);
        }
        setVisible(true);
    }

    public class CloseRestrictionWindow extends TimerTask {
        private RestrictionWindow rw;
        public CloseRestrictionWindow(RestrictionWindow rw) {
            this.rw = rw;
        }

        @Override
        public void run() {
            rw.setVisible(false);
        }
    }
}
